<?php
/**
 * Load the first 10 open medical studies
 * in a box as a short cut
 *
 */
use Fox\Generator;
use Nawa\Messages;
use Fox\Html\Block;
use Fox\Grid;
use Fox\Dao\SqlFragment;
use Nawa\MedicalStudy;

$finder = new MedicalStudy();
$res = $finder->find(new SqlFragment("pa.customerid = ? ",
		array(User::current()->contactid())),
		array('udate' => 'DESC'),
		array(MedicalStudy::$JOIN_PARTNERS),10
);

$grid = new Grid('gMyMedicalStudies');
$grid->fieldcat(array(array('ms_reference','reference'),'label','uname','udate'));
$grid->fieldcat()->switchToObjectMode();
$grid->fieldcat()->field('reference')->width(15);
$grid->fieldcat()->field('udate')->displayTime();
$grid->onClick(Generator::location(Generator::url('medicalstudies','update',null,array('msid' => Generator::useAttribute('msid')))));
$grid->initialize($res);
if(Xview::instance()->ajax())
{
	echo $grid->display();
}
else
{
	$block = new Block('bMedicalStudies',Msg(Messages::BUNDLE,Messages::TITLE_MY_MEDICAL_STUDIES));
	$block->collapsed(false);
	$block->add($grid);
	return $block;
}